package org.ala.tiktools.generator.mybatis.creator.dao_shard;

import org.ala.tiktools.generator.mybatis.config.info.Part;
import org.ala.tiktools.generator.mybatis.creator.dao.DaoInfo;
import org.ala.tiktools.generator.mybatis.creator.entity.EntityInfo;
import org.ala.tiktools.generator.mybatis.creator.entity.fields.EntityFieldsInfo;
import org.ala.tiktools.generator.mybatis.creator.entity.pagerCountDO.PagerCountInfo;
import org.ala.tiktools.generator.mybatis.creator.order_by.OrderByInfo;
import org.ala.tiktools.generator.mybatis.creator.query.QueryInfo;
import org.ala.tiktools.generator.mybatis.creator.shard.ShardRouterInfo;
import org.ala.tiktools.generator.mybatis.dbinfo.TableInfo;
import org.ala.tiktools.generator.mybatis.tools.Tools;

/**
 * @author ala
 * @date 2025-01-08 17:04
 */
public class DaoShardInfo extends DaoInfo {

    protected PagerCountInfo pc;

    protected String annotationShard, annotationShardClassName;
    protected String annotationShardRouter, annotationShardRouterClassName;
    protected String annotationShardTransaction, annotationShardTransactionClassName;

    protected String routerDO, routerDOClassName,
                        routerDOList, routerDOListClassName,
                        routerQuery, routerQueryClassName,
                        routerMU, routerMUClassName;

    protected String afterPager, afterPagerClassName;

    protected String pageCountDO;

    protected boolean shardAutoCreateTable;


    public static DaoShardInfo build(Part p, TableInfo t, EntityInfo e, QueryInfo q, OrderByInfo ob, ShardRouterInfo[] rs, PagerCountInfo pc, EntityFieldsInfo fe) {
        DaoShardInfo d = new DaoShardInfo();
        d.e = e; d.q = q; d.t = t; d.ob = ob; d.fe = fe;
        d.pc = pc;

        d.pkg = p.getOut().getDao().getPkg();
        d.className = Tools.lowToUpFirst(Tools.hump(t.getName())) + p.getOut().getDao().getSuffix();

        d.annotation = p.getOut().getDao().getAnnotation();
        String[] ss = d.annotation.split("\\.");
        d.annotationName = ss[ss.length-1];

        d.mutileUpdate = p.getOut().getDao().getMutileUpdate();
        ss = d.mutileUpdate.split("\\.");
        d.mutileUpdateName = ss[ss.length-1];

        d.annotationShard = p.getOut().getShard().getAnnotationShard();
        d.annotationShardClassName = Tools.upHumpParseName(d.annotationShard);

        d.annotationShardRouter = p.getOut().getShard().getAnnotationShardRouter();
        d.annotationShardRouterClassName = Tools.upHumpParseName(d.annotationShardRouter);

        d.annotationShardTransaction = p.getOut().getShard().getAnnotationShardTransaction();
        d.annotationShardTransactionClassName = Tools.upHumpParseName(d.annotationShardTransaction);

        d.routerDO = rs[0].getPkg() + "." + rs[0].getClassName();
        d.routerDOClassName = Tools.upHumpParseName(d.routerDO);

        d.routerDOList = rs[1].getPkg() + "." + rs[1].getClassName();
        d.routerDOListClassName = Tools.upHumpParseName(d.routerDOList);

        d.routerQuery = rs[2].getPkg() + "." + rs[2].getClassName();
        d.routerQueryClassName = Tools.upHumpParseName(d.routerQuery);

        d.routerMU = rs[3].getPkg() + "." + rs[3].getClassName();
        d.routerMUClassName = Tools.upHumpParseName(d.routerMU);

        d.afterPager = p.getOut().getShard().getAfterPager();
        d.afterPagerClassName = Tools.upHumpParseName(d.afterPager);

        d.pageCountDO = p.getOut().getShard().getPagerCount();

        d.shardAutoCreateTable = p.getOut().getShard().isShardAutoCreateTable();

        d.imports.add("java.util.List");
        d.imports.add(e.getPkg() + "." + e.getClassName());
        d.imports.add(q.getPkg() + "." + q.getClassName());
        d.imports.add(p.getOut().getDao().getAnnotation());
        d.imports.add(p.getOut().getDao().getPagement());
        d.imports.add(p.getOut().getDao().getPager());
        d.imports.add(p.getOut().getShard().getPagerCount());
        d.imports.add(fe.getPkg() + "." + fe.getClassName());
        d.imports.add(d.pc.getPkg() + "." + d.pc.getClassName());
        d.imports.add(d.ob.getPkg() + "." + d.ob.getClassName());
        d.imports.add(d.annotation);
        d.imports.add(d.mutileUpdate);
        d.imports.add(d.annotationShard);
        d.imports.add(d.annotationShardRouter);
        d.imports.add(d.annotationShardTransaction);
        d.imports.add(d.routerDO);
        d.imports.add(d.routerDOList);
        d.imports.add(d.routerQuery);
        d.imports.add(d.routerMU);
        d.imports.add(d.afterPager);

        return d;
    }

    public String getAnnotationShard() {
        return annotationShard;
    }

    public void setAnnotationShard(String annotationShard) {
        this.annotationShard = annotationShard;
    }

    public String getAnnotationShardClassName() {
        return annotationShardClassName;
    }

    public void setAnnotationShardClassName(String annotationShardClassName) {
        this.annotationShardClassName = annotationShardClassName;
    }

    public String getAnnotationShardRouter() {
        return annotationShardRouter;
    }

    public void setAnnotationShardRouter(String annotationShardRouter) {
        this.annotationShardRouter = annotationShardRouter;
    }

    public String getAnnotationShardRouterClassName() {
        return annotationShardRouterClassName;
    }

    public void setAnnotationShardRouterClassName(String annotationShardRouterClassName) {
        this.annotationShardRouterClassName = annotationShardRouterClassName;
    }

    public String getAnnotationShardTransaction() {
        return annotationShardTransaction;
    }

    public void setAnnotationShardTransaction(String annotationShardTransaction) {
        this.annotationShardTransaction = annotationShardTransaction;
    }

    public String getAnnotationShardTransactionClassName() {
        return annotationShardTransactionClassName;
    }

    public void setAnnotationShardTransactionClassName(String annotationShardTransactionClassName) {
        this.annotationShardTransactionClassName = annotationShardTransactionClassName;
    }

    public String getRouterDO() {
        return routerDO;
    }

    public void setRouterDO(String routerDO) {
        this.routerDO = routerDO;
    }

    public String getRouterDOClassName() {
        return routerDOClassName;
    }

    public void setRouterDOClassName(String routerDOClassName) {
        this.routerDOClassName = routerDOClassName;
    }

    public String getRouterDOList() {
        return routerDOList;
    }

    public void setRouterDOList(String routerDOList) {
        this.routerDOList = routerDOList;
    }

    public String getRouterDOListClassName() {
        return routerDOListClassName;
    }

    public void setRouterDOListClassName(String routerDOListClassName) {
        this.routerDOListClassName = routerDOListClassName;
    }

    public String getRouterQuery() {
        return routerQuery;
    }

    public void setRouterQuery(String routerQuery) {
        this.routerQuery = routerQuery;
    }

    public String getRouterQueryClassName() {
        return routerQueryClassName;
    }

    public void setRouterQueryClassName(String routerQueryClassName) {
        this.routerQueryClassName = routerQueryClassName;
    }

    public String getRouterMU() {
        return routerMU;
    }

    public void setRouterMU(String routerMU) {
        this.routerMU = routerMU;
    }

    public String getRouterMUClassName() {
        return routerMUClassName;
    }

    public void setRouterMUClassName(String routerMUClassName) {
        this.routerMUClassName = routerMUClassName;
    }

    public PagerCountInfo getPc() {
        return pc;
    }

    public void setPc(PagerCountInfo pc) {
        this.pc = pc;
    }

    public String getAfterPager() {
        return afterPager;
    }

    public void setAfterPager(String afterPager) {
        this.afterPager = afterPager;
    }

    public String getAfterPagerClassName() {
        return afterPagerClassName;
    }

    public void setAfterPagerClassName(String afterPagerClassName) {
        this.afterPagerClassName = afterPagerClassName;
    }

    public boolean isShardAutoCreateTable() {
        return shardAutoCreateTable;
    }

    public void setShardAutoCreateTable(boolean shardAutoCreateTable) {
        this.shardAutoCreateTable = shardAutoCreateTable;
    }

    public String getPageCountDO() {
        return pageCountDO;
    }

    public void setPageCountDO(String pageCountDO) {
        this.pageCountDO = pageCountDO;
    }
}
